All Questions
Tagged with stringsimmutability
4 questions
-1votes
1answer
361views
In which cases and examples String in Java is not immutable? [duplicate]
If Strings are immutable in Java, why is the output of this code 2GB, instead of 1GB? class Laptop { String memory = "1GB"; } class Workshop { public static void main(String args[]) { ...
1vote
2answers
1kviews
What's the difference of an object being final and an object being immutable in java?
final String str = "do not change me"; str = "why not?"; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed ...
86votes
11answers
34kviews
Why is String immutable in Java?
I couldn't understand the reason of it. I always use String class like other developers, but when I modify the value of it, new instance of String created. What might be the reason of immutability ...
8votes
5answers
7kviews
A string is immutable, so why are they not all constants?
The string type is immutable. We can use the const keyword with strings in high level language like .NET. My understanding of 'const' means constant (it remains the same, we can't change the value). ...